'use strict';

/**
 * @ngdoc function
 * @name webApp.controller:ReadingCtrl
 * @description
 * # ReadingCtrl
 * Controller of the webApp
 */
angular.module('webApp')
  .controller('ReadingCtrl', function ($scope,$ionicLoading,cookie,promiseMainText,$filter,$location) {
    //正文
    var filter = _.memoize(function(data){
      return $filter('trustHtml',data)
    })();
    $scope.$on('$stateChangeSuccess',function() {
      $scope.mainText = {};
      if(cookie.getCookie('newsId') && $location.$$path == '/root/reading'){
        $ionicLoading.show({
          template: '加载中...'
        });
        promiseMainText.articleMain(cookie.getCookie('newsId')).then(function(data){
          data.article.content = filter(data.article.content);
          data.article.title = filter(data.article.title);
          data.article.origin = filter(data.article.origin);
          $scope.mainText = data;
          $ionicLoading.hide();
        });
      }
    });
  });
